package com.kuyun.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kuyun.entity.Comment;
import com.kuyun.service.CommentService;

@Controller
@RequestMapping(value = "/comment")
public class CommentController {

	@Resource
	private CommentService commentService;

	// 趣事评论管理
	@RequestMapping(value = "/showComment")
	public String showComment(HttpSession session, Model model) {
		List<Comment> commentList = commentService.findAllComment();
		Integer i = 1;
		for (Comment comment : commentList) {
			comment.setSequnce(i);
			i++;
		}
		model.addAttribute("commentList", commentList);
		return "comment";
	}

	// 趣事删除
	@RequestMapping(value = "/delComment", method = RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> delFunsType(Integer commentId) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		boolean flag = commentService.delComment(commentId);
		if (flag) {
			resultMap.put("result", "true");
		} else {
			resultMap.put("result", "false");
		}
		return resultMap;
	}

}
